﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KPIS.GERP.GBMS.BLL;

namespace KPIS.GERP.GBMS.APP_UI
{
    public partial class CommandPanel : System.Web.UI.UserControl
    {
        private CommandControl cmdFac = new CommandControl();
        public event EventHandler Inserted;
        public event EventHandler Updated;
        public event EventHandler Deleted;
		public bool IsFormValid { get; set; }
        
		public bool SetBackGroundTransparentcy
		{
			get { return false; }
			set
			{
				blockCommand.Style["background-color"] = "transparent";
				bool x = value;
			}
		}


        protected void Page_Load(object sender, EventArgs e)
        {
            IsFormValid = false;
        }

        protected void ShowGrid_Click(object sender, EventArgs e)
        {
            cmdFac.GridCommand(Parent.FindControl("panelList"), Parent.FindControl("panelGrid"), panelCommand);
        }        
        
        protected void AddNew_Click(object sender, EventArgs e)
        {
            cmdFac.AddNewCommand(Parent.FindControl("panelList"), Parent.FindControl("panelGrid"), panelCommand);
            
        }

        protected void Edit_Click(object sender, EventArgs e)
        {
            cmdFac.EditCommand(Parent.FindControl("panelList"), Parent.FindControl("panelGrid"), panelCommand);
        }

        protected void Cancel_Click(object sender, EventArgs e)
        {
            cmdFac.CancelCommand(Parent.FindControl("panelList"), Parent.FindControl("panelGrid"), panelCommand);
        }

        protected void Save_AddNew_Click(object sender, EventArgs e)
        {             
            OnInsertCommand(e);
        }

        protected void Save_Edit_Click(object sender, EventArgs e)
        {
            OnUpdateCommand(e);
            cmdFac.IsFormValid = IsFormValid;
            cmdFac.ViewCommand(Parent.FindControl("panelList"), Parent.FindControl("panelGrid"), panelCommand);
        }

        protected void Delete_Click(object sender, EventArgs e)
        {
            OnDeleteCommand(e);
        }

        public void MapControl()
        {
            cmdFac.ViewCommand(Parent.FindControl("panelList"), Parent.FindControl("panelGrid"), panelCommand);
        }

        public void RefreshGrid()
        {
            cmdFac.GridCommand(Parent.FindControl("panelList"), Parent.FindControl("panelGrid"), panelCommand);
        }

        protected void OnInsertCommand(EventArgs e)
        {
            string strSQL;
            DataTable dtb;
            strSQL = "SELECT ";
           if (Inserted != null)
            {
                Inserted(this, e);
            }
        }
        protected void OnUpdateCommand(EventArgs e)
        {
            if (Updated != null)
            {
                Updated(this, e);
            }
        }

        protected void OnDeleteCommand(EventArgs e)
        {
            if (Deleted != null)
            {
                Deleted(this, e);
            }
        }
    }
}